function xmlhttpPost(strURL, formname, responsediv, responsemsg, update) {
    _xmlhttpPost(strURL, formname, responsediv, responsemsg, update, getquerystring(formname), false);
}

function xmlhttpPost_(strURL, formname, responsediv, responsemsg, update, query) {
	_xmlhttpPost(strURL, formname, responsediv, responsemsg, update, query, false);
}

function xmlhttpPostwait(strURL, formname, responsediv, responsemsg, update, query) {
	_xmlhttpPost(strURL, formname, responsediv, responsemsg, update, getquerystring(formname), true);
}

function _xmlhttpPost(strURL, formname, responsediv, responsemsg, update, query, wait) {
    var xmlHttpReq = false;
    var self = this;
    self.xmlHttpReq = new XMLHttpRequest();
    self.xmlHttpReq.open('POST', strURL, !wait);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if (update == true){
    self.xmlHttpReq.onreadystatechange = function() {
        	if (self.xmlHttpReq.readyState == this.DONE) 
        		updatepage(self.xmlHttpReq.responseText, responsediv);
        	else
        		updatepage(responsemsg, responsediv);
       	}
    }
    self.xmlHttpReq.send(query);
}

function getquerystring(formname) {
    var elements = document.forms[formname].elements;
	var query ="";
	for (var i = 0; i < elements.length; i++)
	 query += (query.length > 0 ? "&" : "") 
	 		   + escape(elements[i].name)+"=" 
	 		   + escape(elements[i].value ? elements[i].value : "").replace(/\+/g, "%2B");
   
    return query;
}

function updatepage(str, responsediv){
	document.getElementById(responsediv).innerHTML = str;
}